home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 415_02 / rtti / include / String.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-04  |  2.0 KB  |  74 lines

  1. #ifndef _STRING_HH
  2. #define _STRING_HH
  3.  
  4. /* %Z%%I%       %G% %U% %W% */
  5. /*
  6.  * COMPONENT_NAME: (COMINC) Common Header File for RTTI
  7.  *
  8.  * ORIGINS: 27
  9.  *
  10.  * (C) COPYRIGHT International Business Machines Corp. 1992
  11.  * This work was supported by a grant from International Business
  12.  * Machines, Inc. These procedures are contributed to the public domain
  13.  * by International Business Machines Inc. "AS IS" without any warranty
  14.  * of any kind including the warranty of merchantability or fitness
  15.  * for a particular purpose.
  16.  *
  17.  * This is free software. Feel free to redistribute and/or modify it.
  18.  * Please send us e-mail and let us know if you have any problems
  19.  * or suggestions.
  20.  *
  21.  * Arindam Banerji
  22.  * axb@cse.nd.edu
  23.  *
  24.  */
  25.  
  26. #ifndef   _KERNEL
  27. #include   <iostream.h>
  28. #endif   // !_KERNEL
  29. #include   <string.h>
  30. // String.hh
  31. // This defines the string class .
  32.  
  33. const   int  INPUTBUFSIZE = 512 ;
  34.  
  35. class string
  36. {
  37.  private :
  38.     struct   srep {
  39.            char   *s ; // pointer to data
  40.            int    n ; // reference count
  41.            srep() { n = 1 ; }
  42.           } ; // the internal representation format
  43.     srep    *p ;  // the actual repreesntation
  44.  
  45.  public  :
  46.     string ( const char *) ;
  47.     string() ;
  48.     string ( const string &) ;
  49.     string&  operator= ( const char *) ;
  50.     string&  operator= (const string &) ;
  51.     ~string () ;
  52.     char& operator[] (int i ) ;
  53.     operator char *()  ;
  54. #ifndef    _KERNEL
  55.     friend ostream& operator << (ostream &, const string &) ;
  56.     friend istream& operator >> (istream &, string &) ;
  57. #endif  // ! _KERNEL
  58.     void    display(void) ;
  59.  
  60.     friend int operator== ( const string &x, const char *s)
  61.      { return strcmp(x.p->s, s) == 0 ; }
  62.  
  63.     friend int operator== ( const string &x, const string &y)
  64.      { return strcmp(x.p->s, y.p->s) == 0 ; }
  65.  
  66.     friend int  operator!= (const string &x, const char *s)
  67.       { return strcmp(x.p->s, s) != 0 ; }
  68.  
  69.     friend int  operator!= (const string &x, const string &y)
  70.       { return strcmp(x.p->s, y.p->s) != 0 ; }
  71. } ;
  72.  
  73. #endif    // _STRING_HH
  74.